import sys
import os

# 存储任务的列表
tasks = []

# 任务管理器的主要功能
class TaskManager:

    @staticmethod
    def init_task(task_description):
        tasks.append(task_description)
        print(f"任务已初始化: {task_description}")
        
    @staticmethod
    def add_task(task_description):
        tasks.append(task_description)
        print(f"任务已添加: {task_description}")

    @staticmethod
    def complete_task(task_index):
        try:
            completed_task = tasks.pop(task_index)
            print(f"任务已完成: {completed_task}")
        except IndexError:
            print("无效的任务索引")

    @staticmethod
    def list_tasks():
        if not tasks:
            print("暂无任务")
        else:
            print("任务列表:")
            for i, task in enumerate(tasks, 1):
                print(f"{i}. {task}")

    @staticmethod
    def delete_task(task_index):
        try:
            deleted_task = tasks.pop(task_index)
            print(f"任务已删除: {deleted_task}")
        except IndexError:
            print("无效的任务索引")

# 命令行界面
def main():
    while True:
        print("\n任务管理工具")
        print("0. 初始化任务")
        print("1. 添加任务")
        print("2. 标记任务为已完成")
        print("3. 查看任务列表")
        print("4. 删除任务")
        print("5. 退出")
        
        choice = input("请选择操作 (1/2/3/4/5): ")
        
        if choice == "0":
            task_description = input("请初始化任务: ")
            TaskManager.init_task(task_description)
        elif choice == "1":
            task_description = input("请输入任务描述: ")
            TaskManager.add_task(task_description)
        elif choice == "2":
            task_index = int(input("请输入要标记为已完成的任务索引: "))
            TaskManager.complete_task(task_index - 1)
        elif choice == "3":
            TaskManager.list_tasks()
        elif choice == "4":
            task_index = int(input("请输入要删除的任务索引: "))
            TaskManager.delete_task(task_index - 1)
        elif choice == "5":
            print("谢谢使用，再见！欢迎再来")
            break
        else:
            print("无效的选择，请重新选择。")

if __name__ == "__main__":
    main()
